package com.smarthome.base.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.smarthome.base.dao.ShSysHeartbeatDao;
import com.smarthome.base.dao.base.BaseDao;
import com.smarthome.base.service.ShSysHeartbeatService;
import com.smarthome.base.service.base.BaseServiceImpl;
import com.smarthome.domain.bean.ShSysHeartbeat;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
/**
 * 
* @ClassName: ShSysHeartbeatServiceImpl
* @Description: TODO(ShSysHeartbeatService实现类)
* @author cyj
* @date 2015年9月28日 下午9:48:07
*
 */
@Service("shSysHeartbeatService")
public class ShSysHeartbeatServiceImpl extends BaseServiceImpl<ShSysHeartbeat, Long> implements ShSysHeartbeatService{

	@Resource
	private ShSysHeartbeatDao shSysHeartbeatDao;

	@Override
	public BaseDao<ShSysHeartbeat, Long> getDao() {
		return shSysHeartbeatDao;
	}

	@Override
	public DataGrid queryShSysHeartbeat(ShSysHeartbeat querySysHeartbeat, PageHelper page) {
		DataGrid grid = new DataGrid();

		if (!StringUtils.isBlank(page.getOrder())) {
			querySysHeartbeat.setOrderFieldType(page.getOrder());
		}
		if (!StringUtils.isBlank(page.getSort())) {
			querySysHeartbeat.setOrderField(page.getSort());
		}

		int startIndex = (page.getPage() - 1) * page.getRows();
		int endIndex = page.getPage() * page.getRows();
		Long count = shSysHeartbeatDao
				.queryShSysHeartbeatsCount(querySysHeartbeat);
		grid.setTotal(count);

		if (grid.getTotal() > 0 && grid.getTotal() > startIndex) {
			querySysHeartbeat.setStartIndex(startIndex);
			querySysHeartbeat.setEndIndex(endIndex);
			List<ShSysHeartbeat> rows = shSysHeartbeatDao
					.queryShSysHeartbeats(querySysHeartbeat);
			grid.setRows(rows);
		}

		return grid;
	}

}
